package com.alpsoft.spotcheck.util;

import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.util.Log;

/**
 * 按键F1，F2按键监听广播。
 * @author Nasir
 *
 */
public class FunkeyListener extends BroadcastReceiver {

	@Override
	public void onReceive(Context context, Intent intent) {
		boolean defaultdown = false;
		int keycode = intent.getIntExtra("keycode", 0);
		boolean keydown = intent.getBooleanExtra("keydown", defaultdown);
		 Log.i("ServiceDemo", "receiver:keycode=" + keycode + "keydown=" +
		 keydown);
		// 左侧下按键
		if (keycode == 133 && keydown) {
			GlobalVar.ts.speak("扫描");
			// sendCmd();
			if("ct".equals(GlobalVar.scanType)){
				GlobalVar.ct.scanREAD();
			}else if("sc".equals(GlobalVar.scanType)){
				GlobalVar.sc.scan();
//				sendCmd();
			}
		}
		
		// 右侧按键
		if (keycode == 134 && keydown) {
			GlobalVar.ts.speak("扫描");
			// sendCmd();
			if("ct".equals(GlobalVar.scanType)){
				GlobalVar.ct.scanREAD();
			}else if("sc".equals(GlobalVar.scanType)){
//				sendCmd();
				GlobalVar.sc.scan();
			}
		}

		if (keycode == 131 && keydown) {//F1的keyCode是131
			GlobalVar.ts.speak("扫描");
			// Toast.makeText(context.getApplicationContext(), "条形码", 0)
			// .show();
			// sendCmd();
			if("ct".equals(GlobalVar.scanType)){
				GlobalVar.ct.scanREAD();
			}else if("sc".equals(GlobalVar.scanType)){
//				sendCmd();
				GlobalVar.sc.scan();
			}
		}

		if (keycode == 132 && keydown) {//F2的keyCode是132
			GlobalVar.ts.speak("扫描");
			// Toast.makeText(context.getApplicationContext(), "条形码", 0)
			// .show();
			// sendCmd();
			if("ct".equals(GlobalVar.scanType)){
				GlobalVar.ct.scanREAD();
			}else if("sc".equals(GlobalVar.scanType)){
//				sendCmd();
				GlobalVar.sc.scan();
			}
			//按下F2,执行扫码
//				GlobalVar.sc.scan();
		}
//		context.unregisterReceiver(this);
	}

}
